package com.atguigu.gmall.common.config;

import com.atguigu.gmall.common.properties.MinioProperties;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(value = MinioProperties.class)       // 作用：1、开启通过实体类读取配置文件的功能   2、把对应的实体类纳入到spring容器中
public class MinioConfiguration {

    @Autowired
    private MinioProperties minioProperties ;

    @Bean
    public MinioClient minioClient() {

        // 创建一个MinioClient对象
        MinioClient minioClient = MinioClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();

        return minioClient ;

    }

}
